<?php
class IndexController extends Zend_Controller_Action
{    
    public function init(){
        $this->view->tituloPagina = "PAINEL INFORMATIVO";
    }
    public function indexAction(){
//        $obArmazenagemRepository = new App_Model_ArmazenagemRepository();
//        $this->view->arArmazenagemLimite = $obArmazenagemRepository->listarArmazenagemLimite();		       					    	        

    	$obProdutoRepository	= new App_Model_ProdutoRepository();
    	$arrParam = array('nu_total_produto' =>0 , 'st_ativo'=>'S' );
    	$this->view->arArmazenagemLimite = $obProdutoRepository->listarTodos( $arrParam );
    	
        $obCompraRepository= new App_Model_CompraRepository();
        $this->view->arCompra = $obCompraRepository->listarTodos(array('order'=>'compra.dt_cadastro desc','limit'=>'4'));                        
        
        $obDistribuicaoRepository = new App_Model_DistribuicaoRepository();        
        $this->view->arDistribuicao = $obDistribuicaoRepository->listarTodos(array('order'=>'distribuicao.dt_cadastro desc','limit'=>'4'));      
    }
    
    public function twitterAction(){
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender();
        try{
            
            $config = array(
                              'callbackUrl'=>'http://www.janelasbrasil.com.br/sisgef/autenticacao/callback-twitter',
                              'siteUrl'=>'https://twitter.com/oauth',
                              'consumerKey'=>'cOmptQqTM90l3QoyER5xw',
                              'consumerSecret'=>'24v5WC1yZmcjLYEwayJ3jhJrCoIFxGun4AMqFCKTXt8'
                            );
            $consumer = new Zend_Oauth_Consumer($config);

            // fetch a request token
            $token = $consumer->getRequestToken();

            // persist the token to storage
            $_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);

            // redirect the user
            $consumer->redirect();
            
            //            $client = $token->getHttpClient($configuration);
//            $client->setUri('http://twitter.com/statuses/update.json');
//            $client->setMethod(Zend_Http_Client::POST);
//            $client->setParameterPost('status', 'Felipe Testando');
//            $response = $client->request();
            
//        $access = $oauth->getAccessToken($_GET, unserialize($_SESSION['request_token']));
//        $twitter  = new  Zend_Service_Twitter('sisgef', 'sisgef2011');
//        $twitter->status->update("Meu teste");
        
//            $http = new Zend_Http_Client('http://twitter.com/statuses/update.xml', array(  
//                'maxredirects' => 0,  
//                'timeout'      => 10,  
//             ));  
//
//             $http->setAuth(  
//                'sisgef',  
//                'sisgef2011',  
//                 Zend_Http_Client::AUTH_BASIC  
//             );  
//
//             $http->setMethod(Zend_Http_Client::POST);  
//             $http->setParameterPost('status', 'Your status message');  
//             $http->request();
        }catch(Exception $e){
            echo $e->getMessage();
        }
    }
}